﻿
; TestController must be restarted before any changes in this file will be used.

; Manual is here: https://lygte-info.dk/project/TestControllerConfigDevice%20UK.html
; versions:
; 20211124 first version
; 20211125 fixed some bugs, added +" " to *:math:unit? to avoid timeout
; 20211126 added :layout: to info controls to resize Setup dialogs
; 20211209 added download recorded data, renamed trace:* to mem:*

; known issues:
; fav:math:unit? returns garbage if unit is single letter - device returns invalid value, 0x0040FFEEE5 instead of 0x00410000, 
;                other :math:unit? work fine
; spec:* are not enabled on some FW versions, it is working with v2.1, not working with v1.13
; fav:mode 0 is not working, other values work, but fav:mode? returns 0 when favourite measurement is Voltage (set in instrument)
;          there is undocumented fav:mode 8, it shows AC+DC, but is not measuring anything  
; mem:date? returns wrong date, 1 month in the future,subtracting 31*24*3600 results 1 day shift on 30-day months
; register for sampling rate for stored recordings is unknown

#metadef
;#metaDebug
#idString Metrix,MTX3281
#name Metrix MTX3281
#handle MTX3281
#replaceText 3283 3281
#replaceText MaxRecords 150
#remove #cmdSetup number dBm Reference 
#remove #cmdSetup number Power Reference
#removeLine Auto-Peak
#removeLine Pt100
#removeLine Pt1000
#removeLine FREQ_dB_MATH
#removeLine dBm_REF_MATH
#removeLine W_REF_MATH
#removeLine VxA_A_MATH
#removeLine MATH
#removeLine PW+_CNT+_MATH
#removeLine PW-_CNT-_MATH
#removeLine References

#metadef
;#metaDebug
#idString Metrix,MTX3282
#name Metrix MTX3282
#handle MTX3282
#replaceText 3283 3282
#replaceText MaxRecords 6500
#remove #cmdSetup number dBm Reference 
#remove #cmdSetup number Power Reference 
#removeLine FREQ_dB_MATH
#removeLine dBm_REF_MATH
#removeLine W_REF_MATH
#removeLine References

#meta
#author tgotic
;#metaDebug
#idString Metrix,MTX3283
#name Metrix MTX3283
#handle MTX3283
#replaceText MaxRecords 6500
#port com
#baudrate 9600
#driver Modbus
#subDriver ascii

; -----------------------------------------------------------------------------
; define commands for modbus registers
; -----------------------------------------------------------------------------
#initCmd                       holding   0x8001 1
#finalCmd                      holding   0x8001 0

#scpiCmd sys:producer?         holding?  0x0001
:readmath: hex(value)
#scpiCmd model?                holding?  0x0002
#scpiCmd getDeviceSN?          holdingL? 0x0003
:readmath: hex(value)
#scpiCmd cal:site?             holding?  0x0005
#scpiCmd cal:date?             holdingL? 0x0006
:readmath: formatDateTime("YYYY-MM-dd HH:mm:ss",msToDateGMT((value)*1000))
#scpiCmd cal:next?             holdingL? 0x0008
:readmath: formatDateTime("YYYY-MM-dd HH:mm:ss",msToDateGMT((value)*1000))
#scpiCmd getDeviceSW?          holding?  0x000A
:readmath: replace((binConvBit((value),8,8)+","+binConvBit((value),0,8)),",",".")
#scpiCmd sys:addr?             holding?  0x000E
; too dangerous, no interface to change address back to default value 
;#scpiCmd sys:addr             holding   0x000E (value)
#scpiCmd sys:date?             holdingL? 0x000F
:readmath: formatDateTime("YYYY-MM-dd HH:mm:ss",msToDateGMT((value)*1000))
#scpiCmd sys:date              holdingL  0x000F (dateTomsGMT(date())/1000)
#scpiCmd sys:lang?             holding?  0x0011
#scpiCmd sys:lang              holding   0x0011 (value)
#scpiCmd getDeviceHW?          holding?  0x0013
:readmath: binConvString(int(value))
:string:

#scpiCmd fav:math:a?           holdingF? 0x1000
#scpiCmd fav:math:a            holdingF  0x1000 (value)
#scpiCmd fav:math:b?           holdingF? 0x1002
#scpiCmd fav:math:b            holdingF  0x1002 (value)
#scpiCmd fav:mode?             holding?  0x1007
#scpiCmd fav:mode              holding   0x1007 (value)
#scpiCmd fav:math:unit?        holdingL? 0x1008
:readmath: replace(binConvString(int(value),1,3,"",1,0),"\x80","Ω")+" "
#scpiCmd fav:math:unit         holdingL  0x1008 (binConv(int(bytes(replace((""+value),"Ω","\x80"))),0,3,0,1))
#scpiCmd fav:enable?           holding?  0x100B                                                                                                                                     
:readmath: (value)>0?1:0
#scpiCmd fav:enable            holding   0x100B (value)

#scpiCmd volt:math:a?          holdingF? 0x2000
#scpiCmd volt:math:a           holdingF  0x2000 (value)
#scpiCmd volt:math:b?          holdingF? 0x2002
#scpiCmd volt:math:b           holdingF  0x2002 (value)
#scpiCmd volt:math:unit?       holdingL? 0x2004
:readmath: replace(binConvString(int(value),1,3,"",1,0),"\x80","Ω")+" " 
#scpiCmd volt:math:unit        holdingL  0x2004 (binConv(int(bytes(replace((""+value),"Ω","\x80"))),0,3,0,1))

#scpiCmd curr:math:a?          holdingF? 0x3000
#scpiCmd curr:math:a           holdingF  0x3000 (value)
#scpiCmd curr:math:b?          holdingF? 0x3002
#scpiCmd curr:math:b           holdingF  0x3002 (value)
#scpiCmd curr:math:unit?       holdingL? 0x3004
:readmath: replace(binConvString(int(value),1,3,"",1,0),"\x80","Ω")+" " 
#scpiCmd curr:math:unit        holdingL  0x3004 (binConv(int(bytes(replace((""+value),"Ω","\x80"))),0,3,0,1))

#scpiCmd res:math:a?           holdingF? 0x4000
#scpiCmd res:math:a            holdingF  0x4000 (value)
#scpiCmd res:math:b?           holdingF? 0x4002
#scpiCmd res:math:b            holdingF  0x4002 (value)
#scpiCmd res:math:unit?        holdingL? 0x4004
:readmath: replace(binConvString(int(value),1,3,"",1,0),"\x80","Ω")+" " 
#scpiCmd res:math:unit         holdingL  0x4004 (binConv(int(bytes(replace((""+value),"Ω","\x80"))),0,3,0,1))

#scpiCmd freq:math:a?          holdingF? 0x5000
#scpiCmd freq:math:a           holdingF  0x5000 (value)
#scpiCmd freq:math:b?          holdingF? 0x5002
#scpiCmd freq:math:b           holdingF  0x5002 (value)
#scpiCmd freq:math:unit?       holdingL? 0x5004
:readmath: replace(binConvString(int(value),1,3,"",1,0),"\x80","Ω")+" " 
#scpiCmd freq:math:unit        holdingL  0x5004 (binConv(int(bytes(replace((""+value),"Ω","\x80"))),0,3,0,1))

#scpiCmd coupling?             holding?  0x6000
#scpiCmd coupling              holding   0x6000 (value)
#scpiCmd volt:impedance?       holding?  0x6001
#scpiCmd volt:impedance        holding   0x6001 (value)

#scpiCmd volt:filter?          holding?  0x7000
#scpiCmd volt:filter           holding   0x7000 (value)
#scpiCmd freq:range:V?         holding?  0x7001
#scpiCmd freq:range:V          holding   0x7001 (value)
#scpiCmd mode?                 holding?  0x7002
#scpiCmd mode                  holding   0x7002 (value)
#scpiCmd dbm:ref?              holdingL? 0x7003
#scpiCmd dbm:ref               holdingL  0x7003 (value)
#scpiCmd power:ref?            holdingL? 0x7005
#scpiCmd power:ref             holdingL  0x7005 (value)
#scpiCmd range?                holdingS? 0x7007
#scpiCmd range                 holding   0x7007 (value)
#scpiCmd func?                 holding?  0x7008
#scpiCmd func                  holding   0x7008 (value)
#scpiCmd temp:probe?           holding?  0x7009
#scpiCmd temp:probe            holding   0x7009 (value)
#scpiCmd temp:unit?            holding?  0x700A
#scpiCmd temp:unit             holding   0x700A (value)

#scpiCmd rel:enable?           holding?  0x700B
:readmath: value>0?1:0
#scpiCmd rel:enable            holding   0x700B (value)
#scpiCmd rel:ref?              holdingF? 0x700C
#scpiCmd rel:ref               holdingF  0x700C (value)
#scpiCmd rel:diffA?            holdingF? 0x700E
#scpiCmd rel:diffP?            holdingF? 0x7010

#scpiCmd hold?                 holding?  0x7012
#scpiCmd hold                  holding   0x7012 (value)

#scpiCmd surv:enable?          holding?  0x7013
:readmath: value>0?1:0
#scpiCmd surv:enable           holding   0x7013 (value)
#scpiCmd surv:date:start?      holdingL? 0x7014
:readmath: formatDateTime("YYYY-MM-dd HH:mm:ss",msToDateGMT((value)*1000))
#scpiCmd surv:date:stop?       holdingL? 0x7016
:readmath: formatDateTime("YYYY-MM-dd HH:mm:ss",msToDateGMT((value)*1000))
#scpiCmd surv:min?             holdingF? 0x7018
#scpiCmd surv:date:min?        holdingL? 0x701A
:readmath: formatDateTime("YYYY-MM-dd HH:mm:ss",msToDateGMT((value)*1000))
#scpiCmd surv:max?             holdingF? 0x701C
#scpiCmd surv:date:max?        holdingL? 0x701E
:readmath: formatDateTime("YYYY-MM-dd HH:mm:ss",msToDateGMT((value)*1000))

#scpiCmd freq:range:Hz?        holding?  0x7026
#scpiCmd freq:range:Hz         holding   0x7026 (value)

; spec enable 16, disable 0
#scpiCmd spec:enable?          holding?  0x7027
:readmath: value>0?1:0
#scpiCmd spec:enable           holding   0x7027 (value)
;error in percent
#scpiCmd spec:percent?         holdingF? 0x7028
;error offset in digits
#scpiCmd spec:digits?          holding?  0x702A

#scpiCmd sys:beeper?           holding?  0x8000
#scpiCmd sys:beeper            holding   0x8000 (value)

#scpiCmd mem:page?             holding?  0x9000
#scpiCmd mem:page              holding   0x9000 (value)
#scpiCmd mem:sampling?         holdingL? 0x9001
:readmath: int(value/1000)
#scpiCmd mem:sampling          holdingL  0x9001 ((value)*1000)
; read mem:first?>-1 mem:session #, mem:next?>-1 mem:session # - not reliable!
#scpiCmd mem:first?            holdingS? 0x9003
#scpiCmd mem:next?             holdingS? 0x9004
#scpiCmd mem:sessions?         holdingS? 0x9005
; number of records in current session
#scpiCmd mem:records?          holding?  0x9006
#scpiCmd mem:session?          holdingS? 0x9007
#scpiCmd mem:session           holding   0x9007 (value)
#scpiCmd mem:date?             holdingL? 0x9008
:readmath: formatDateTime("YYYY-MM-dd HH:mm:ss",msToDateGMT((value)*1000))
;:readmath: formatDateTime("YYYY-MM-dd HH:mm:ss",msToDateGMT(((value)-31*24*3600)*1000))
#scpiCmd mem:coupling?         holding?  0x900A
:readmath: getElement("AC DC AC+DC",value)
#scpiCmd mem:temp:unit?        holding?  0x900B
:readmath: getElement("°C °F K",value)
#scpiCmd mem:temp:probe?       holding?  0x900C
:readmath: getElement("Pt100 Pt1000 TC-J TC-K",value)
; get number of saved functions
#scpiCmd mem:funcs?            holding?  0x900D
; type of main measurement (Voltage, Current, ...)
#scpiCmd mem:func0?            holding?  0x900E
:readmath: getElement("Voltage Current Resistance Continuity Diode Frequency Capacitance Temperature",value)
#scpiCmd mem:func1?            holding?  0x900F
:readmath: getElement("_ FREQ PER MATH dB dBm REF_dBm PK+ PK- CF W Ref_Ω VxA A DC+ DC- PW+ PW- CNT+ CNT-",value)
#scpiCmd mem:func2?            holding?  0x9010
:readmath: getElement("_ FREQ PER MATH dB dBm REF_dBm PK+ PK- CF W Ref_Ω VxA A DC+ DC- PW+ PW- CNT+ CNT-",value)
#scpiCmd mem:func3?            holding?  0x9011
:readmath: getElement("_ FREQ PER MATH dB dBm REF_dBm PK+ PK- CF W Ref_Ω VxA A DC+ DC- PW+ PW- CNT+ CNT-",value)
; set ID of function to get records from (0 to mem:funcs?)
#scpiCmd mem:func              holding   0x9012 (value)
; ID of new session
#scpiCmd mem:new?              holding?  0x9013
; get value form mem:record position and from mem:func, unknown multiplier (10 = 10mV, 10=10V) 
#scpiCmd mem:valueX?            holdingF? 0x9014
; start recording
#scpiCmd mem:rec               holding   0x9016 1
; create new session (mem:new?) and start recording (mem:rec)
#scpiCmd mem:new               holding   0x9017 1
; stop recording
#scpiCmd mem:stop              holding   0x9018 1
; is recording active
#scpiCmd mem:rec?              holding?  0x9019
; erase data from current session 
#scpiCmd mem:erase             holding   0x901A 1
; erase data from all sessions
#scpiCmd mem:clear             holding   0x901B 1
; number of records in active session, -1 for inactive session (mem:rec? = 0)
#scpiCmd mem:count?            holdingS? 0x901C
; select value (0-based index) to be read with mem:value?
#scpiCmd mem:record            holding   0x901D (value)
; get value form mem:record position and from mem:func
; undocumented, but working!
#scpiCmd mem:value?            holdingF? 0x901E
;#scpiCmd mem:value?            holdingL? 0x901E
;:readmath: value==2139095039?invalidValue(1):(value==8388608?0:binConvFloat(int(value),0,4))

#scpiCmd value?                holdingF? 0xA000
#scpiCmd value2?               holdingF? 0xA002
#scpiCmd value3?               holdingF? 0xA004
#scpiCmd value4?               holdingF? 0xA006

; -----------------------------------------------------------------------------
; custom commands
; -----------------------------------------------------------------------------
#scpiCmd user none
:setvar: userVar=inputValue

#scpiCmd user? none?
:readmath: varExists("userVar")?userVar:1
 
; -----------------------------------------------------------------------------
; reading values
; -----------------------------------------------------------------------------

#verifyDevice 3283 model?

#askMode mode?

#mayModifyMode fav:enable

;delay in seconds
#modeChangeDelay 10

; delay in miliseconds
;#cmdDelayTime 100

; not working
;#answerTimeout 3000

;delay in seconds
#readingDelay 5

#value Voltage V D5 Voltage,Diode
#value Current A D5 Current
#value Resistance Ω D5 Resistance,Continuity
#value Frequency Hz D5 Frequency
#value Capacity F D5 Capacity
#value Temperature _ D4 Temperature
#value Display2 _ D5
#value Display3 _ D5
#value Display4 _ D5

#askValues value?;value2?;value3?;value4?

#interfaceType BMM
#interface readValue  0
#interface readValue2 1
#interface readValue3 2
#interface readValue4 3

; -----------------------------------------------------------------------------
; main modes
; -----------------------------------------------------------------------------

#cmdMode Voltage 0
mode 0;[500]

#cmdMode Current 1
mode 1;[500]

#cmdMode Resistance 2
mode 2;[500]

#cmdMode Continuity 3
mode 3;[500]

#cmdMode Diode 4
mode 4;[500]

#cmdMode Frequency 5
mode 5;[500]

#cmdMode Capacity 6
mode 6;[500]

#cmdMode Temperature 7
mode 7;[500]

; -----------------------------------------------------------------------------
; Setup
; -----------------------------------------------------------------------------

; -----------------------------------------------------------------------------
; Voltage
; -----------------------------------------------------------------------------
#cmdSetup comboboxhot Range Voltage
:read: range?
:write: range #;[500]
:string:
100mV     0
1V        1
10V       2
100V      3
1000V     4
Auto-Peak -2
Auto      -1
;Auto-Peak 65534
;Auto      65535

#cmdSetup comboboxhot Coupling Voltage
:read: coupling?
:write: coupling #;[500]
AC 0
DC 1
AC+DC 2

#cmdSetup comboboxhot Impedance Voltage
:read: volt:impedance?
:write: volt:impedance #;[500]
10/20MΩ 0
1GΩ 1
:tip: Input impedance on 100mV DC and AC+DC (10MΩ or 1GΩ) and 1V DC (20MΩ or 1GΩ)

#cmdSetup comboboxhot Filter Voltage
:read: volt:filter?
:write: volt:filter #;[500]
Off 0
On 1
:tip: Improve frequency rejection in low VDC
 
#cmdSetup comboboxhot Secondary Voltage
:read:  func?
:write: func #;[500]
:tip: Check Table of secondary functions, page 24 in Users manual
None              0
FREQ_PER_MATH     1
FREQ_dB_MATH      2
dBm_REF_MATH      3
PK+_PK-_CF        4
W_REF_MATH        5
VxA_A_MATH        6

#cmdSetup numberDual MATH Voltage
:read: volt:math:a?;volt:math:b?
:write: volt:math:a #;[500];volt:math:b #;[500]
:tip: MATH A and B coefficients in formula value = A * readout + B
_ _ _ A 
_ _ _ B 

#cmdSetup text MATH_Unit Voltage
:read: volt:math:unit?
:write: volt:math:unit #;[500]
:string:
:tip: Unit for MATH, max 3 letters
3

; -----------------------------------------------------------------------------
; Current
; -----------------------------------------------------------------------------
#cmdSetup comboboxhot Range Current
:read: range?
:write: range #;[500]
:string:
1000µA    0
10mA      1
100mA     2
1000mA    3
10A       4
100A      5
Auto-Peak -2
Auto      -1

#cmdSetup comboboxhot Coupling Current
:read: coupling?
:write: coupling #;[500]
AC 0
DC 1
AC+DC 2

#cmdSetup comboboxhot Secondary Current
:read:  func?
:write: func #;[500]
:tip: Check Table of secondary functions, page 24 in Users manual 
None           0
FREQ_PER_MATH  1
PK+_PK-_CF     4
W_REF_MATH     5

#cmdSetup numberDual MATH Current
:read: curr:math:a?;curr:math:b?
:write: curr:math:a #;[500];curr:math:b #;[500]
:tip: MATH A and B coefficients in formula value = A * readout + B
_ _ _ A 
_ _ _ B 

#cmdSetup text MATH_Unit Current
:read: curr:math:unit?
:write: curr:math:unit #;[500]
:string:
:tip: Unit for MATH, max 3 letters
3

; -----------------------------------------------------------------------------
; Resistance
; -----------------------------------------------------------------------------
#cmdSetup comboboxhot Range Resistance
:read: range?
:write: range #;[500]
1kΩ       0
10kΩ      1
100kΩ     2
1MΩ       3
10MΩ      4
50MΩ      5
Auto      -1

#cmdSetup comboboxhot Secondary Resistance
:read:  func?
:write: func #;[500]
None     0
Math    11

#cmdSetup numberDual MATH Resistance
:read: res:math:a?;res:math:b?
:write: res:math:a #;[500];res:math:b #;[500]
:tip: MATH A and B coefficients in formula value = A * readout + B
_ _ _ A 
_ _ _ B 

#cmdSetup text MATH_Unit Resistance
:read: res:math:unit?
:write: res:math:unit #;[500]
:string:
:tip: Unit for MATH, max 3 letters
3

; -----------------------------------------------------------------------------
; Capacitance
; -----------------------------------------------------------------------------
#cmdSetup comboboxhot Range Capacitance
:read: range?
:write: range #;[500]
10nF       0
100nF      1
1µF        2
10µF       3
100µF      4
1mF        5
10mF       6
Auto       -1

; -----------------------------------------------------------------------------
; Frequency
; -----------------------------------------------------------------------------
#cmdSetup comboboxhot Range Frequency
:read: freq:range:Hz?
:write: freq:range:Hz #;[500]
<900kHz      0
>900kHz      1

#cmdSetup comboboxhot Voltage Frequency
:read: freq:range:V?
:write: freq:range:V #;[500]
100mV      0
1V         1
10V        2
100V       3
1000V      4

#cmdSetup comboboxhot Secondary Frequency
:read:  func?
:write: func #;[500]
None            0
PER_DC+_MATH    7
PER_DC-_MATH    8
PW+_CNT+_MATH   9
PW-_CNT-_MATH   10

#cmdSetup numberDual MATH Frequency
:read: freq:math:a?;freq:math:b?
:write: freq:math:a #;[500];freq:math:b #;[500]
:tip: MATH A and B coefficients in formula value = A * readout + B
_ _ _ A 
_ _ _ B 

#cmdSetup text MATH_Unit Frequency
:read: freq:math:unit?
:write: freq:math:unit #;[500]
:string:
:tip: Unit for MATH, max 3 letters
3

; -----------------------------------------------------------------------------
; Temperature
; -----------------------------------------------------------------------------
#cmdSetup comboboxhot Range Temperature
:read: range?
:write: range #;[500]
-100..+100°C      0
-200..+300°C      1
-200..+1200°C     2

#cmdSetup comboboxhot Units Temperature
:read: temp:unit?
:write: temp:unit #
°C 0
°F 1
K  2

#cmdSetup comboboxhot Probe Temperature
:read: temp:probe?
:write: temp:probe #;[500]
Pt100     0
Pt1000    1
TC-J      2
TC-K      3

; -----------------------------------------------------------------------------
; Diode
; -----------------------------------------------------------------------------
#cmdSetup info Notice Diode
_
Nothing to change here
; -----------------------------------------------------------------------------
; Continuity
; -----------------------------------------------------------------------------
#cmdSetup info Notice Continuity
_
Nothing to change here

; -----------------------------------------------------------------------------
; System
; -----------------------------------------------------------------------------
#cmdSetup info Instrument_time System
:read: sys:date?
:layout:
_
_

#cmdSetup button Synchronize System
:write: sys:date
:update: Instrument_time
:tip: Synchronize instrument time with computer time

#cmdSetup info Modbus_address System
:read: sys:addr?
;:write: sys:addr #
;_ 1 247

#cmdSetup comboboxhot Language System
:read: sys:lang?
:write: sys:lang #;[500]
English 0
French  1

#cmdSetup checkbox Beeper System
:read: sys:beeper?
:write: sys:beeper;[500]
_ 0 1

; -----------------------------------------------------------------------------
; Traceability
; -----------------------------------------------------------------------------
#cmdSetup info Model Traceability
:read: model?
_
_

#cmdSetup info Serial Traceability
:read: getDeviceSN?
_
_

#cmdSetup info Firmware Traceability
:read: getDeviceSW?
_
_

#cmdSetup info Hardware Traceability
:read: getDeviceHW?
:string:
_
_

#cmdSetup info FactoryID Traceability
:read: sys:producer?
:string:
_
_

#cmdSetup info Calibration_Site Traceability
:read: cal:site?
_
_

#cmdSetup info Last_Calibration Traceability
:read: cal:date?
_
_

#cmdSetup info Next_Calibration Traceability
:read: cal:next?
:layout:
_
_

; -----------------------------------------------------------------------------
; Relative measurements
; -----------------------------------------------------------------------------
#cmdSetup number Reference Relative 
:read: rel:ref?
:write: rel:ref #;[500]
:enable: Relative.Relative 
_ _ _

#cmdSetup buttonsOn Relative Relative
:read: rel:enable?
:write: rel:enable #;[500]
:tip: Enable relative measurement
:update: Reference
Off 0
On 1

; -----------------------------------------------------------------------------
; Reference values
; -----------------------------------------------------------------------------
#cmdSetup numberInt dBm References 
:read: dbm:ref?
:write: dbm:ref #;[500]
Ω 1 10000

#cmdSetup numberInt Power References 
:read: power:ref?
:write: power:ref #;[500]
Ω 1 10000

; -----------------------------------------------------------------------------
; Favourite mode
; -----------------------------------------------------------------------------
#cmdSetup comboboxhot Mode Favourite
:read: fav:mode?
:write: fav:mode #;[500]
:string:
:tip: *BUG* It won't change back to Voltage mode
:enable: !Favourite.Favourite
Voltage          0
Current          1
Resistance       2
Continuity       3
Diode            4
Frequency        5
Capacitance      6
Temperature      7

#cmdSetup numberDual MATH Favourite
:read: fav:math:a?;fav:math:b?
:write: fav:math:a #;[500];fav:math:b #;[500]
:tip: MATH A and B coefficients in formula value = A * readout + B
_ _ _ A 
_ _ _ B 

#cmdSetup text MATH_Unit Favourite
:read: fav:math:unit?
:write: fav:math:unit #;[500]
:string:
:tip: Unit for MATH, displays garbage for single letter unit
3

#cmdSetup buttonsOn Favourite Favourite
:read: fav:enable?
:write: fav:enable #;[500]
:tip: Enable favourite measurement
:updatemodechange:
Off 0
On 1

; -----------------------------------------------------------------------------
; Surveilance info
; -----------------------------------------------------------------------------
#cmdSetup info Started Surveilance
:read: surv:date:start?
:layout:
_ _

#cmdSetup info Finished Surveilance
:read: surv:date:stop?
_ _

#cmdSetup info Min Surveilance
:read: surv:min?
_ _

#cmdSetup info Max Surveilance
:read: surv:max?
_ _

#cmdSetup info Min@ Surveilance
:read: surv:date:min?
_ _

#cmdSetup info Max@ Surveilance
:read: surv:date:max?
_ _

#cmdSetup buttonsOn Surveilance Surveilance
:read: surv:enable?
:write: surv:enable #;[500]
:update: Surveilance.
Off 0
On  1

; -----------------------------------------------------------------------------
; Specification info
; -----------------------------------------------------------------------------
#cmdSetup info Accuracy Specification 
:read: spec:percent?
:format: X2
:updatemodechange:
:layout:
:tip: Turn Specification ON to fetch accuracy values  
%_of_reading 
_ 

#cmdSetup info Accuracy Specification 
:read: spec:digits?
:updatemodechange:
digits
±

#cmdSetup buttonsOn Specification Specification
:read: spec:enable?
:write: spec:enable #;[500]
:update: Accuracy
:tip: Some models don't have this functionality (digits=-2)
Off 0
On  1

; -----------------------------------------------------------------------------
; Memory
; -----------------------------------------------------------------------------
#cmdSetup indicatornum Recording Memory
:read: mem:rec?
Off 0 yellow
On  1 red

#cmdSetup numberInt Max_records Memory 
:read: mem:page?
:write: mem:page #
:format: INT
:tip: Max records per session.\nRecording stops when reaching max records. 
_ 1 MaxRecords

#cmdSetup numberInt Sampling Memory 
:read: mem:sampling?
:write: mem:sampling #
:format: INT
:tip: Take sample every n-th second. (from 1s to 23:59:59s)
s 1 86399

#cmdSetup button Clear_sessions Memory
:write: mem:clear
:tip: Clear all sessions and stored data
:update: Sessions Session Session_info Measurements

#cmdSetup button New_session Memory
:write: mem:new
:tip: Start recording data to a new session
:update: Recording

#cmdSetup info Sessions Memory
:read: mem:sessions?
_
_

#cmdSetup info Sessions Memory
:read: mem:new?
:layout:
_
New:

#cmdSetup numberInt Session Memory
:read: mem:session?
:write: mem:session #
:update: Session_info
:tip: ID of selected session
_ 0 9

#cmdSetup info Session_info Memory
:read: mem:date?
_
Date:

#cmdSetup info Session_info Memory
:read: mem:records?
:layout:
_
Records:

#cmdSetup info Session_info Memory
:read: mem:next?
:layout:
_
Next:


#cmdSetup info Measurement Memory
:read: mem:func0?
_
_

#cmdSetup info Measurement Memory
:read: mem:func1?
_
1:

#cmdSetup info Measurement Memory
:read: mem:func2?
_
2:

#cmdSetup info Measurement Memory
:read: mem:func3?
:layout:
_
3:

#cmdSetup button Rec Memory
:write: mem:rec
:tip: Start recording to current session
:update: Recording

#cmdSetup button Stop Memory
:write: mem:stop
:tip: Stop recording
:update: Recording Sessions Session_info Measurement

#cmdSetup button Erase Memory
:write: mem:erase
:tip: Erase current session data
:update: Sessions Session Session_info Measurement

; -----------------------------------------------------------------------------
; Setup selectors
; -----------------------------------------------------------------------------
#cmdSetup info Active_mode
:read: mode?
:readmath: getElement("Voltage Current Resistance Continuity Diode Frequency Capacitance Temperature",value)
:updatemodechange:
_
_

#cmdSetup comboboxhot Function
:read: user?
:write: user #
Mode          1
Favourite     2
Relative      3
Specification 4
Surveilance   5 
System        6
Traceability  7
References    8
Memory        9

#cmdSetup selector No_Function
Function
:updatemodechange:
1 No_mode
2 Favourite.
3 Relative.
4 Specification.
5 Surveilance.
6 System.
7 Traceability.
8 References.
9 Memory.

#cmdSetup selector No_mode
:read: mode?
0 Voltage.
1 Current.
2 Resistance.
3 Continuity.
4 Diode.
5 Frequency.
6 Capacitance.
7 Temperature.

; -----------------------------------------------------------------------------
; Hold
; -----------------------------------------------------------------------------
#cmdSetup comboboxhot Hold
:read: hold?
:write: hold #;[500]
Off  0
Hold 1
Auto 2

; -----------------------------------------------------------------------------
; Scripting
; -----------------------------------------------------------------------------
#otherList
var nx = deviceRead(handle, "mem:sessions?");
var n = 0
while ((n < 10) && (nx > 0)) do
   deviceWrite(handle, "mem:session " + n);
   var start = deviceRead(handle, "mem:date?");
   menuItem[n] = "MEM" + n + ":" + start + ".csv";
   nx = nx - 1;
   n = n + 1;
endwhile;

#otherData
var n = getMatch(name, "[0-9]");
deviceWrite(handle, "mem:session " + n);
var header = deviceRead(handle, "mem:func0?");
if (header == "Voltage" || header == "Current")
   header = header + deviceRead(handle, "mem:coupling?"); 
elseif (header == "Temperature")
   header = header + " " + deviceRead(handle, "mem:temp:probe?"); 
   header = header + " " + deviceRead(handle, "mem:temp:unit?"); 
endif;
header = handle + "." + header;
;var header = handle + "." + deviceRead(handle, "mem:func0?");
var columns = deviceRead(handle,"mem:funcs?");
n = 1;
while (n < columns) do
    header = header + "," + handle + "." + deviceRead(handle, "mem:func" + n + "?");
    n = n + 1;
endwhile;

if (columns > 1)
; reset mem:func to 0
   deviceWrite(handle, "mem:func 0");
endif;

tableInitHeader("index,"+header);
var records = deviceRead(handle, "mem:records?");
popupShowProgressAsync("Downloading " + name + " data from " + handle, records * columns);
n = 0;
while (n < records) do
    deviceWrite(handle, "mem:record " + n);
	var value = deviceRead(handle, "mem:value?");
    popupShowProgressSetPosition(n * columns);
    if (columns == 1)
       tableAddRow(n, value);
    else
        deviceWrite(handle, "mem:func 1");
        var value1 = deviceRead(handle,"mem:value?");
        popupShowProgressSetPosition(n * columns + 1);
        if (columns == 2)
           tableAddRow(n, value, value1);
        else
            deviceWrite(handle, "mem:func 2");
            var value2 = deviceRead(handle, "mem:value?");
            popupShowProgressSetPosition(n * columns + 2);
            if (columns == 3)
               tableAddRow(n, value, value1, value2);
            else
                deviceWrite(handle, "mem:func 3");
                var value3 = deviceRead(handle, "mem:value?");
                popupShowProgressSetPosition(n * columns + 3);
                tableAddRow(n, value, value1, value2, value3);
            endif; 
        endif;
        deviceWrite(handle, "mem:func 0"); 
    endif;
    n = n + 1; 
endwhile;
popupShowProgressSetPosition(records * columns + 1);
